<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="js/vue.js" type="text/javascript">
			
		</script>
	</head>
	<body>
		<div id="app">
			<cn></cn>
			<cn></cn>
			<cn></cn>
		</div>
		
		<template id = "temp">
			<div>
				<h2>当前计数:{{counter}}</h2>
				<button @click="add" type="button">+</button>
				<button @click="sub" type="button">-</button>
			</div>
			
		</template>
		
		<script type="text/javascript">
			const app = new Vue({
				el:"#app",
				components:{
					cn:{
						template:"#temp",
						// data:{counter:0},错误写法
						data(){
							return {counter:0};
						},
						methods:{
							add:function(){
								this.counter++;
							},
							sub:function(){
								this.counter--;
							}
						}
					}
				}
			})
		</script>
	</body>
</html>
